package cn.bytengine.stem.events;

import cn.bytengine.stem.functional.invoker.Invoker;
import cn.bytengine.stem.functional.invoker.RunnableInvoker;

import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;

public class AsyncRegisterOption implements RegisterOption {
    private final Supplier<ExecutorService> executorServiceSupplier;

    public AsyncRegisterOption(Supplier<ExecutorService> executorServiceSupplier) {
        this.executorServiceSupplier = executorServiceSupplier;
    }

    @Override
    public Invoker option(String eventName, Invoker invoker) {
        return args -> executorServiceSupplier.get().execute(new RunnableInvoker(invoker, args));
    }
}
